package com.woniuxy.yoga.coach.service.mq;

import com.woniuxy.yoga.coach.dao.mapper.CoachLogMapper;
import com.woniuxy.yoga.coach.dao.model.CoachLog;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class LoginCoachLogConsumer {

    @Resource
    private CoachLogMapper coachLogMapper;

    //登录日志记录的消息队列
    @RabbitListener(queuesToDeclare = {@Queue(name = "coachLog.sendMassage")})
    @RabbitHandler
    public void comsumer(Map<String,Object> message) throws Exception {
        //获取数据
        String logTime = (String) message.get("logTime");
        String logCoach = (String) message.get("logCoach");
        String logDesc = (String) message.get("logDesc");
        //对象转换
        CoachLog coachLog = new CoachLog();
        coachLog.setLogTime(logTime);
        coachLog.setLogCoach(logCoach);
        coachLog.setLogDesc(logDesc);
        //新增数据
        coachLogMapper.insert(coachLog);
    }
}
